<template>
  <div class="muying">
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide"><img src="../../assets/img/shouye/shouye-muying/haipao_mamabibei.png" alt=""></div>
        <div class="swiper-slide"><img src="../../assets/img/shouye/shouye/lunbodazao.png" alt=""></div>
        <div class="swiper-slide"><img src="../../assets/img/shouye/shouye/lunbo_xunli.png" alt=""></div>
        <div class="swiper-slide"><img src="../../assets/img/shouye/shouye/lunbodazao.png" alt=""></div>
        <div class="swiper-slide"><img src="../../assets/img/shouye/shouye/lunbo_xunli.png" alt=""></div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
    <!--奶粉专区-->
    <ul class="tuijian-ul">
      <h3><span></span>奶粉专区<span></span></h3>
      <li>
        <div class="jinrituijian">
          <router-link :to="{name: 'naifen'}">
            <img src="../../assets/img/shouye/shouye-muying/haibao_mamibaobei.png" alt="">
          </router-link>
        </div>
        <ul class="shangpin-ul">
          <li v-for="good in Arr">
            <router-link :to="{name: 'shangpinxiangqing', params: {good}}">
              <img :src="good.src" alt="">
            </router-link>
            <h5>{{good.name}}</h5>
            <span>¥{{good.price}}</span>
          </li>
        </ul>
      </li>
    </ul>
    <ul class="tuijian-ul">
      <h3><span></span>纸尿裤专区<span></span></h3>
      <li>
        <div class="jinrituijian">
          <router-link :to="{name: 'naifen'}">
            <img src="../../assets/img/shouye/shouye-muying/haibao_mamibaobei.png" alt="">
          </router-link>
        </div>
        <ul class="shangpin-ul">
          <li v-for="good in zArr">
            <router-link :to="{name: 'shangpinxiangqing', params: {good}}">
              <img :src="good.src" alt="">
            </router-link>
            <h5>{{good.name}}</h5>
            <span>¥{{good.price}}</span>
          </li>
        </ul>
      </li>
    </ul>
    <!--猜你喜欢-->
    <div class="baopin">
      <h3><span></span>猜你喜欢<span></span></h3>
      <ul class="baopin-ul">
        <li>
          <ul class="baopinchanpin-ul">
            <li v-for="good in arr">
              <router-link :to="{name: 'shangpinxiangqing', params: {good}}">
                <div class="good-img" >
                  <img :src="good.src" alt="">
                </div>
              </router-link>
              <h4>{{good.name}}</h4>
              <h5>¥{{good.price}}</h5>
              <img class="baopin-img" src="../../assets/img/shouye/shouye-meishi/baopin.png" alt="">
            </li>
          </ul>
        </li>
      </ul>
    </div>
    <div class="up" @click="toTop()" v-if="isUP">
      <img src="../../assets/img/shouye/tuijian-xuanliyanzhuang/toTop.png"/>
    </div>
  </div>
</template>
<script>
  import * as $ from 'jquery'
  import * as Swiper from 'swiper'
  import "swiper/dist/css/swiper.css"
  import '../../style/mySwiper.css'
  import Vue from 'vue'
  //  import * as BootStrap from 'bootstrap'
  export default {
    data () {
      return {
        isUP: false,
        Arr: [],
        arr: [],
        zArr: []
      }
    },
    mounted() {
      new Swiper['default']('.swiper-container', {
        loop: true,
        autoplay: true,
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
          clickable: true,
          bulletActiveClass: 'my-bullet-active',
        },
      }),
        window.addEventListener('scroll', this.menu);
      this.tuijianGet();
    },
    methods: {
      toTop () {
        if(document.documentElement){
          document.documentElement.scrollTop = 0;
        }else{
          document.body.scrollTop = 0;
        }
      },
      menu() {
        this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
        if(this.scroll > 0){
          //显示 a 标签
          this.isUP = true;
        }else{
          //隐藏 a 标签
          this.isUP = false;
        }
      },
      top () {
        window.scrollTo(0,0)
      },
      tuijianGet() {
        //  发起get请求
        //  设置代理服务器转发的域
        Vue.axios.get('/api/get', {
//              get传递的query参数
//            params: {
//              name: 'along',
//              age: 32
//            }
        }).then( (response) => {
          //  成功之后的回调
//          console.log(response.data);
          this.arr = response.data;
//          console.log(this.arr);
          for (let i = 0 ; i < this.arr.length; i ++) {
            if (this.arr[i].sc === '奶粉') {
              this.Arr.push(this.arr[i]);
            } else if (this.arr[i].sc === '纸尿裤') {
              this.zArr.push(this.arr[i]);
            }
          }
        }).catch( (error) => {
          //  请求出错的处理
          console.log(error)
        });
      }
    },
    created () {
      this.top();
    }
  }
</script>
<style scoped>
  @import url("../../../node_modules/swiper/dist/css/swiper.css");
  /*@import url("../../../node_modules/bootstrap/dist/css/bootstrap.css");*/
  .muying {
    margin-top: 2rem;
    background: #f2f2f2;
    padding-bottom: 3rem;
    position: relative;
    width: 100%;
  }
  .swiper-container{
  }
  .swiper-slide img{
    width: 100%;
  }
  /*奶粉专区*/
  .muying .tuijian-ul {
    background: #fff;
    margin-top: -0.1rem;
    margin-bottom: 0.5rem;
    padding-top: 0.1rem;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
  }
  .muying .jinrituijian {
    text-align: center;
  }
  .muying .jinrituijian img{
    width: 90%;
  }
  .shangpin-ul {
    width: 100%;
    margin-left: 0.3rem;
    margin-bottom: 0.2rem;
  }
  .shangpin-ul>li{
    width: 4.8rem;
    display: inline-block;
    text-align: center;
    border: 1px solid #ccc;
    margin: 0.1rem;
  }
  .shangpin-ul>li img{
    max-width: 3rem;
    max-height: 3rem;
  }
  .shangpin-ul>li h5{
    font-size: 0.6rem;
  }
  .shangpin-ul>li span{
    display: block;
    font-size: 0.6rem;
    color: #e83d41;
  }
  .tuijian-ul h3, .baopin h3 {
    text-align: center;
    font-family: MicrosoftYaHei;
    font-size: 0.9rem;
    font-weight: normal;
    font-stretch: normal;
    line-height: 1rem;
    letter-spacing: 0rem;
    color: #4d4d4d;
    margin: 0.2rem 0;
  }
  .tuijian-ul h3 > span, .baopin h3 > span {
    display: inline-block;
    width: 1rem;
    height: 0.3rem;
    border-top: 1px solid #ccc;
    margin: 0 0.3rem;
  }
  /*猜你喜欢*/
  .baopin{
    margin-top: 0.5rem;
    background: #fff;
  }
  .baopinchanpin-ul {
    text-align: center;
  }
  .baopinchanpin-ul li {
    display: inline-block;
    text-align: center;
    border: 1px solid #ccc;
    position: relative;
    width: 6.5rem;
    height: 8rem;
    margin: 0.5rem;
  }
  .baopinchanpin-ul li .good-img{
    width: 5rem;
    height: 4rem;
    margin: 1rem auto;
  }
  .baopinchanpin-ul li .good-img img {
    max-width: 5rem;
    max-height: 4rem;
    line-height: 4rem;
  }
  .baopinchanpin-ul li h4{
    font-family: MicrosoftYaHei;
    font-size: 0.7rem;
    font-weight: normal;
    font-stretch: normal;
    line-height: 1rem;
    letter-spacing: 0rem;
    color: #4d4d4d;
  }
  .baopinchanpin-ul li h5 {
    font-family: MicrosoftYaHei;
    font-size: 0.7rem;
    font-weight: normal;
    font-stretch: normal;
    line-height: 1rem;
    letter-spacing: 0rem;
    color: #e53e42;
  }
  .baopin-img{
    position: absolute;
    top: 0;
    left:0;
    width: 15%;
  }
  .up {
    width: 1.5rem;
    position: fixed;
    bottom: 3rem;
    right: 0.3rem;
  }
  .up img {
    width: 100%;
  }
</style>
